<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>组合式API - 单击改变颜色</title>

</head>

<body>
    <script src="https://cdn.staticfile.org/vue/3.0.5/vue.global.js"></script>
    <div id="Application">
        <h3>单击那行文本，该文本变色，其他不变</h3>
        <ul>
            <li v-for="item in data" :key="item.id">

                <button type="button" @click="myClick(item.id)" :class="(ins===item.id)?'red':'blue'">
                    {{item.title}}
                </button>

            </li>
        </ul>
    </div>
    <script>
        const App = Vue.createApp({
            setup() {
                const data = Vue.ref([
                    { id: 1, title: "one" },
                    { id: 2, title: "two" },
                    { id: 3, title: "three" },
                ])
                //记录当前列表ID
                const ins = Vue.ref(0)
                //赋值当前点击的id
                function myClick(id) {
                    ins.value=id;
                };


                return { ins, data, myClick }
            }
        })
        App.mount("#Application")
    </script>
    <style>
        .red {
            color: tomato;
        }
    </style>
</body>

</html>